package com.github.kezhenxu94.playground.java.junit4;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.Description;
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.notification.RunListener;

public class StudyJUnitCore {

	@Before
	public void before() {
		System.out.println("Before");
	}

	@After
	public void after() {
		System.out.println("After");
	}

	@Test(expected = Exception.class)
	public void test0() {
		System.out.println("通过 JUnitCore 调用测试类");
		throw new RuntimeException();
	}

	public static void main(String[] args) {
		final JUnitCore jUnitCore = new JUnitCore();
		jUnitCore.addListener(new RunListener() {
			@Override
			public void testFinished(Description description) throws Exception {
				System.out.println("Test finished");
				super.testFinished(description);
			}
		});
		Result result = jUnitCore.run(StudyJUnitCore.class);
		System.out.println(result.getFailureCount());
	}
}
